package com.jg.framework.utils.spring;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringBeanUtil implements ApplicationContextAware{
	
	private static ApplicationContext context;

	/**
	 * 获取bean
	 * 
	 * @param name
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static <T> T getBean(String name) {
		return (T)context.getBean(name);
	}

	@Override
	public void setApplicationContext(ApplicationContext context)
			throws BeansException {
		SpringBeanUtil.context = context;
	}
}
